package me.zhengjie;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        int n = 10;
        int result = fibonacci(n);
        System.out.println("Fibonacci number at position " + n + " is: " + result);

        String[] strs = {"flower", "flow", "flowight"};
        System.out.println(strs.length);
        System.out.println(longestCommonPrefix(strs));


        String html = "<p><img src=\"//file/images/show_518141303_1709297113205-2024030108461928.jpg\" alt=\"\" data-href=\"\" style=\"width: 100%;\"/></p>";
        String regex = "<img.*?src=\"(.*?)\".*?>";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(html);
        StringBuilder sb = new StringBuilder();
        int lastIndex = 0;
        while (matcher.find()) {
            // 获取src属性值
            String src = matcher.group(1);
            // 进行重新赋值
            String newSrc = "http://wx.drzh-atmr.cn"+src;
            // 拼接字符串
            sb.append(html.substring(lastIndex, matcher.start())).append("<img src=\"").append(newSrc).append("\" alt=\"\" data-href=\"\" style=\"width: 100%;\">");
            lastIndex = matcher.end();
        }
        sb.append(html.substring(lastIndex));
        String newHtml = sb.toString();
        System.out.println(newHtml);

    }

    public static int fibonacci(int n) {
        if (n == 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }

        int[] dp = new int[n + 1];
        dp[0] = 0;
        dp[1] = 1;

        for (int i = 2; i <= n; i++) {
            dp[i] = dp[i - 1] + dp[i - 2];
        }

        return dp[n];
    }


    public static String longestCommonPrefix(String[] strs) {
        if (strs.length == 0) return "";
        for (int i = 0; i < strs[0].length(); i++) {
            char c = strs[0].charAt(i);
            for (int j = 1; j < strs.length; j++) {
                if (i == strs[j].length() || strs[j].charAt(i) != c) {
                    return strs[0].substring(0, i);
                }
            }
        }
        return strs[0];
    }
}